<template>
  <div>
    <div class="box">
      <div class="box1" @click="onConfirm" disabled="“disabled”">点击签到</div>
    </div>
    <div class="t_box">考勤记录</div>
    <van-swipe-cell v-for="(item, index) in list" :key="index">
      <van-cell
        :title="item.t_name"
        :value="item.t_status"
        size="large"
        :label="item.t_time"
      />
      <template #right>
        <van-button
          style="height: 70px"
          @click="del_btn(item.t_id)"
          square
          type="danger"
          text="删除"
        />
      </template>
    </van-swipe-cell>
  </div>
</template>
<script>
export default {
  inject: ['reload'],
  data() {
    return {
      show: false,
      radio: "1",
      list: [],
      attendance: "已完成",
      username: "",
      id: "",
    };
  },
  created() {
    // let userId = localStorage.getItem("userId");
    this.userName = localStorage.getItem("userName");

    this.ask(this.userName);
  },
  methods: {
    ask(name) {
      this.axios({
        method: "post",
        url: "http://localhost:3000/find_atten",
        data: {
          username: name,
        },
      }).then((res) => {
        //   console.log(res.data.data);
        this.list = res.data.data;
        console.log(this.list);
      });
    },

    onConfirm() {
      // console.log(this.userName);
      this.axios({
        method: "post",
        url: "http://localhost:3000/attendance",
        data: {
          username: this.userName,
          attendance: this.attendance,
        },
        processData: false,
        contentType: false,
      }).then((res) => {
        console.log(res);
      });
      this.reload()
      //  this.ask(this.userName);
      //  window.location.reload()
     
    },

    del_btn(i) {
      this.axios({
        method: "post",
        url: "http://localhost:3000/del_atten",
        data: {
          t_id: i,
        },
      }).then((res) => {
        console.log(res);
      });
      this.reload()
      // this.ask(this.userName);
      //  window.location.reload()
    },
  },
};
</script>

<style scoped>
.box {
  width: 100vw;
  padding: 5px 0;
  border-bottom: 1px solid #fff;
}
.box1 {
  width: 100px;
  height: 100px;
  border-radius: 50%;
  border: none;
  line-height: 100px;
  text-align: center;
  margin: 0 auto;
  background-color: rgb(156, 236, 236);
}
.t_box {
  height: 50px;
  line-height: 50px;
  padding: 0 3%;
  font-size: 20px;
  font-weight: bold;
}
</style>